package Controler;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Information.HireInfo;
import Model.HireInfoDAO;
import Model.NewsDAO;

public class scanHireInfo extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public scanHireInfo() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		HireInfoDAO hireInfoDAO = new HireInfoDAO();
		ArrayList<HireInfo> hireArrayList = new ArrayList<HireInfo>();
		try {
			hireArrayList = hireInfoDAO.SeeAllHireInfo();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String result = "";
		for (HireInfo hireInfo : hireArrayList)
		{
			result+="<div class='panel panel-primary'><div class='panel-heading'>";
			result+="<h3 class='panel-title'>"+"企业名:"+hireInfo.getEName()+"</h3></div>";
			result+="<div class='panel-body'>";
			result+="<p>"+"类型:"+hireInfo.getEType()+"</p>";
			result+="<p>"+"邮箱:"+hireInfo.getEEmail()+"</p>";
			result+="<p>"+"电话:"+hireInfo.getETel()+"</p>";
			result+="<p>"+"地址:"+hireInfo.getEAddress()+"</p>";
			result+="<p>"+"邮编:"+hireInfo.getEPostCode()+"</p>";
			result+="<p>"+"工作职位:"+hireInfo.getJob()+"</p>";
			result+="<p>"+"招聘人数:"+hireInfo.getHireTotal()+"</p>";
			result+="<p>"+"工作城市:"+hireInfo.getCity()+"</p>";
			result+="<p>"+"工作描述:"+hireInfo.getDescribe()+"</p>";
			result+="</div>";
			result+="<div class='panel-footer'>";
			result+="<span>"+"发布时间:"+hireInfo.getPublishTime()+"</span>";
//			result+="<span>"+"点击量:"+hireInfo.getTotalClick()+"</span></div>";
			result+="</div></div>";
		}
		out.print(result);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
